-- 在用户参数设置好键对
-- "1":"device1"
-- "2":"device2"
-- Modbus设置单独上传，根据id去用户参数里面找到id对应的设备名称，在上传
function(tm,td,ex)
    if not td or #td < 1 then
    return {}
    end
    local template = {
        DeviceName = ex[tostring(td[1].i)]  or "defaultname",
        Timestamp = os.time()*1000,
        DataMap = {Va = 221.5}
    }
    template.DataMap = tm
    return template
    end

    {
        "DeviceName" : "device1",
        "Timestamp": 1672281095000,
        "DataMap" : {"a":10, "b":11}
    }



-- 在用户参数设置好键对
-- "1":"device1"
-- "2":"device2"
-- Modbus设置单独上传，根据id去用户参数里面找到id对应的设备名称，在上传
function(tm,td,ex)
    if not td or #td < 1 then return {} end
    local template = {}
    for index, value in ipairs(td) do
            local id = value.i
        table.insert(template,{["slaveNo"..id] = value.v})
    end
    return template
    end

    {
        "slaveNo1": {
            "IA": 12,
            "Temp": 10.2
         },
        "slaveNo2": {
            "IA": 13,
            "Temp": 10
        }
    }

    function(tm,td,ex)
        if not td or #td < 1 then
        return {}
        end
        local template = tm
        template.newname = ex[tostring(td[1].i)] or "defaultname"
        return template
        end

function(tm,td,ex)
if not td or #td < 1 then
return {}
end
local name = ex[tostring(td[1].i)] or td[1].i
local result = {
    ts = os.time()*1000,
    values = {va = 221.5}
}
result.values = tm
local template = {}
template[name] = {result}
return template
end

        {
            "device1": [
                {
                    "ts": 1672281095000,
                    "values": {
                        "a": 10,
                        "b": 11
                    }
                }
            ]
        }
        end




        
        function(tm,td,ex)
            if not td or #td < 1 then
            return {}
            end
            local template = tm
            template.newname = ex[tostring(td[1].i)] or "defaultname"
            return template
            end
        [{"1":{"state":"ON"}}]
function (sub)
    if #sub < 1 then return end
    local devTemp = {}
    for index, value in ipairs(sub) do
        for key, val in pairs(value) do
            local temp = {}
            for k, v in pairs(val) do
                if v == "ON" then
                    temp[k] = "1"
                elseif v == "OFF" then
                    temp[k] = "0"
                else
                    temp[k] = val[k]
                end
            end
            table.insert(devTemp, {i=key, v=temp})
        end
    end
    return devTemp
end
        [{"v":{"key1":"10","key2":"20"},"i":"1234"},{"v":{"key1":"30","key2":"40"},"i":"5678"}]


        function (sub)
            if #sub < 1 then return end
            local devTemp = {}
            for index, value in ipairs(sub) do
                for key, val in pairs(value) do
                    table.insert(devTemp, {i=key, v=val})
                end
            end
            return devTemp
        end

        [{"计量空开1":{"state":"ON"}}]
function(tm,td,ex)
    if not td or #td < 1 then
    return {}
    end
    local template = tm
    template.newname = ex[tostring(td[1].i)] or "defaultname"
    return template
end,
function (sub,ex)
    if #sub < 1 then return end
    local devTemp = {}
    for index, value in ipairs(sub) do
        for key, val in pairs(value) do
            local temp = {}
            for k, v in pairs(ex) do
                if key == v then
                    temp["i"] = k
                end
            end
            for k, v in pairs(val) do
                if v == "ON" then
                    val[k] = "1"
                elseif v == "OFF" then
                    val[k] = "0"
                end
            temp["v"] = val
            end
            table.insert(devTemp, temp)
        end
    end
    return devTemp
end